package top.zlcode.friend.controller.question;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.zlcode.common.core.controller.BaseController;
import top.zlcode.common.core.domain.R;
import top.zlcode.common.core.domain.TableDataInfo;
import top.zlcode.friend.aspect.CheckUserAiStatus;
import top.zlcode.friend.aspect.CheckUserStatus;
import top.zlcode.friend.domain.question.dto.QuestionCodeSuggestDTO;
import top.zlcode.friend.domain.question.dto.QuestionQueryDTO;
import top.zlcode.friend.domain.question.vo.QuestionAnalysisVO;
import top.zlcode.friend.domain.question.vo.QuestionCodeSuggestVO;
import top.zlcode.friend.domain.question.vo.QuestionDetailVO;
import top.zlcode.friend.service.question.IQuestionService;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        return questionService.list(questionQueryDTO);
    }

    /**
     * 题目详情
     * @param questionId 题目id
     * @return 题目详情实体
     */
    @CheckUserStatus
    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId) {
        return R.ok(questionService.detail(questionId));
    }

    /**
     * 上一个题目id
     * @param questionId 题目id
     * @return 题目id
     */
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long questionId) {
        return R.ok(questionService.preQuestion(questionId));
    }

    /**
     * 下一个题目id
     * @param questionId 题目id
     * @return 题目id
     */
    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long questionId) {
        return R.ok(questionService.nextQuestion(questionId));
    }

    /**
     * ai一键题目解析功能
     */
    @CheckUserAiStatus
    @GetMapping("/ai/analysis")
    public R<QuestionAnalysisVO> analysis(Long questionId, Integer programType) {
        return R.ok(questionService.analysis(questionId, programType));
    }

    /**
     * ai 代码建议优化
     */
    @CheckUserAiStatus
    @PostMapping("/ai/codeSuggest")
    public R<QuestionCodeSuggestVO> codeSuggest(@RequestBody QuestionCodeSuggestDTO questionCodeSuggestDTO) {
        return R.ok(questionService.codeSuggest(questionCodeSuggestDTO));
    }
}
